import { formatTime } from '../../utils/util';
let mixinList = require('../../common/mixinList');
Page({
    behaviors: [mixinList],
    data: {
        reqUrl: '/api/product/index',
        type: '', //0特惠  1品质  2视频
        showAddCartPopup: false, //展示加入购物车弹窗
        addCartCurrent: null, //加入购物车商品信息
    },
    onLoad(options) {
        let type = Number(options.type);
        wx.setNavigationBarTitle({
            title: ['今日特惠', '平台推荐', '视频看花'][type],
        });
        this.setData({ type });
        this.getList(true);
    },
    getParamsData() {
        //tabs页面特殊的请求参数，需要时在页面内覆盖此方法，默认返回{}\
        const { type } = this.data;
        let params = {};
        if (type === 0) {
            params.special_offer = '1';
        } else {
            params.type = ['', '2', '3'][type];
        }
        return params;
    },
    /**点击加入购物车 */
    openAddcartPopup(e) {
        const { info } = e.currentTarget.dataset;

        if (info.sku === 0)
            return wx.showToast({
                title: '该商品已售空',
                icon: 'none',
            });
        const { imgHost } = this.data;
        const addCartCurrent = {
            product_img: imgHost + info.product_img,
            product_name: info.product_name,
            product_price: info.product_price,
            sku: info.sku,
            unit: info.unit,
            supplier_id: info.supplier.supplier_id,
            supplier_name: info.supplier.title,
            level: info.level,
            norm: info.norm,
            product_id: info.product_id,
            sell_num: info.sell_num,
        };

        this.setData({
            addCartCurrent,
            showAddCartPopup: true,
        });
    },
});
